package com.aaa.service.impl;

import com.aaa.dao.UserDao;
import com.aaa.entity.PageSort;
import com.aaa.entity.User;
import com.aaa.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author ：admin
 * @date ：Created in 2022/6/27 14:11
 * @description：用户业务实现类
 * @modified By：
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;


    @Override
    public Page findAllPageByPlugin(PageSort pageSort) {
        //开始分页
        PageHelper.startPage(pageSort.getPage(),pageSort.getLimit());
        List<User> userList = userDao.findAllUser(pageSort);
        //com.github.pagehelper.Page listPage  = (com.github.pagehelper.Page) userList;
        Page listPage  = (Page) userList;
        return listPage;
    }

    @Override
    public User findUserByName(String username) {
        User user = userDao.findUserByName(username);
        return user;
    }

    @Override
    public User findUserById(Integer userId) {
        User userById = userDao.findUserById(userId);
        return userById;
    }

    @Override
    public int saveUser(User user) {
        int insertNum = userDao.saveUser(user);
        return insertNum;
    }

    @Override
    public int deleteUserById(Integer userid) {
        int delNum = userDao.deleteUserById(userid);
        return delNum;
    }

    @Override
    public int updateUser(User user) {
        int updateNum = userDao.updateUser(user);
        return updateNum;
    }

    @Override
    public User checkLogin(String username) {
        User user = userDao.checkLogin(username);
        return user;
    }

    @Override
    public int resetPwd(User user) {
        return userDao.resetPwd(user);
    }

    @Override
    public List<Map<String, Object>> findAllUserByName(Map map) {
        return userDao.findAllUserByName(map);
    }

    @Override
    public int setCharacter(int userId, int role) {
        int num = userDao.setCharacter(userId, role);
        return num;
    }

    @Override
    public int deleteRoleByUserid(Integer userId) {
        return userDao.deleteRoleByUserid(userId);
    }


}
